package com.definity.toolkit.web.taglib;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.jsp.JspException;

public class DateTag extends BaseTag {

	private static final long serialVersionUID = 5198277380400530300L;

	private Date date;
	
	public DateTag() {
		setPattern("dd/MM/yyyy");
	}
	
	public void setDate(Date date) {
		this.date = date;
	}
	
	@Override
	public int doEndTag() throws JspException {
		SimpleDateFormat sdf = new SimpleDateFormat(getPattern());
		
		Date dt = date;
		if (dt == null)
			dt = new Date();
		
		write(sdf.format(dt));
		
		return super.doEndTag();
	}
	
}
